/*
 * ICommunicationModuleBridge.h
 *
 *  Created on: Dec 12, 2014
 *      Authors: Avihay Avitan & Stefan Farcas
 */

#ifndef ICOMMUNICATIONMODULEBRIDGE_H_
#define ICOMMUNICATIONMODULEBRIDGE_H_
#include <string>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <thread>
#include "../ProtobufMessage/Message.pb.h"
#include "../PassLogger/PassLogger.h"
#include "../ProgressStatus/ProgressStatus.h"

#include "AllUtils.h"

using namespace ProgressStatusSpace;
using namespace std ;
using namespace message;
using namespace LoggerNameSpace;


namespace CommunicationModuleSpace {
/**
 * ICommunicationModuleBridge is an interface defines the communication functionality that is needed to be implemented by any communication module that GSPASS use
 * see [CommunicationModule] section in core.ini file
 */
class ICommunicationModuleBridge {
public:
	ICommunicationModuleBridge();
	virtual ~ICommunicationModuleBridge();
	/**
	 * sending INIT commands and wait for receiving an ACK from satellite.
	 * timeout - the time out duration in seconds for waiting on sending or receiving command
	 * returns true if ACK received, otherwise false
	 */
	virtual bool transmitINITcommand(long timeout)=0;
	/**
	 * sending GO_CMD to satellite. then receiving all data from satellite (and handle all of them). finally receiving END command.
	 * timeout - the time out duration in seconds for waiting on sending or receiving command
	 * receivedDatalogger - is the pass logger related to the current pass process - for logging.
	 * returns true if finished with END, otherwise false
	 */
	virtual bool transmitGOCMD(long timeout, PassLogger * receivedDatalogger)=0;
	/**
	 * send command to satellite
	 * timeout - the time out duration in seconds for waiting on sending or receiving command
	 * commandsContent - commands is a byte array represent as string
	 * returns true if received ACK
	 */
	virtual bool sendCommandToSat(long timeout, string commandsContent)=0;
	/**
	 * sending END command to satellite
	 * timeout - the time out duration in seconds for waiting on sending or receiving command
	 * returns true if sending succeeded.
	 */
	virtual bool sendENDCommand(long timeout)=0;
	/**
	 * check if communication module is ready for pass
	 * returns true if module is ready
	 */
	virtual bool isReadyForPass()=0;

protected:
	/**
	 * low level function to send and waiting for received message
	 * request - message to send
	 * received - pointer to object to be filled with the received message
	 * returns true if success
	 */
	virtual bool sendAndWaitForReceive ( Message request , Message * received )  = 0;
	/**
	 * low level function to send a message
	 * message - message to send
	 * returns true if success
	 */
	virtual bool send(Message message)= 0;
	/**
	 * low level function to receive a message
	 * received - pointer to object to be filled with the received message
	 * returns true if success
	 */
	virtual bool receive (Message * received) = 0;
	/**
	 * low level function to send and waiting for received message with declared timeout
	 * request - message to send
	 * received - pointer to object to be filled with the received message
	 * timeoutsec - the time out duration in seconds for waiting on sending or receiving command
	 * returns true if success
	 */
	virtual bool sendAndWaitForReceiveWithTimeout ( Message request ,Message * received ,  int timeoutsec )= 0;
	/**
	 * low level function to send a message with declared timeout
	 * message - message to send
	 * timeoutsec - the time out duration in seconds for waiting on sending or receiving command
	 * returns true if success
	 */
	virtual bool sendWithTimeout(Message message , int timeoutsec )= 0;
	/**
	 * low level function to receive a message with declared timeout
	 * received - pointer to object to be filled with the received message
	 * timeoutsec - the time out duration in seconds for waiting on sending or receiving command
	 * returns true if success
	 */
	virtual bool receiveWithTimeout (Message * received, int timeoutsec )= 0;
	bool isReady;


};

} /* namespace CommunicationModuleSpace */

#endif /* ICOMMUNICATIONMODULEBRIDGE_H_ */
